﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true" CodeBehind="$safeitemrootname$.aspx.cs" Inherits="$rootnamespace$.$safeitemrootname$" %>

<%@ Register assembly="GrayParrot.Web.Controls" namespace="GrayParrot.Web.Controls" tagprefix="cc1" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <!-- Used By Grid -->
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.10/css/dataTables.bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/responsive/2.0.0/css/responsive.bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.1.0/css/buttons.dataTables.min.css" />   
    <link rel="stylesheet" type="text/css" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yadcf/jquery.dataTables.yadcf.css" /> 

    <script type="text/javascript" lang="javascript" src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.js"></script>   
    <script type="text/javascript" lang="javascript" src="https://cdn.datatables.net/1.10.10/js/dataTables.bootstrap.min.js"></script>   
    <script type="text/javascript" lang="javascript" src="https://cdn.datatables.net/responsive/2.0.0/js/dataTables.responsive.min.js"></script>   
    <script type="text/javascript" lang="javascript" src="https://cdn.datatables.net/responsive/2.0.0/js/responsive.bootstrap.min.js"></script>   
    <script type="text/javascript" lang="javascript" src="https://cdn.datatables.net/select/1.1.0/js/dataTables.select.min.js"></script>  
    <script type="text/javascript" lang="javascript" src="https://cdn.datatables.net/buttons/1.1.0/js/dataTables.buttons.min.js"></script>  
    
    <script type="text/javascript" lang="javascript" src="../Scripts/yadcf/jquery.dataTables.yadcf.js"></script> 
    <!-- Used By Grid -->

    <!-- Common -->
    <script type="text/javascript" lang="javascript" src="/Scripts/GrayParrot.Core.js"></script> 
    <script type="text/javascript" lang="javascript" src="/Scripts/GrayParrot.DataTables.js"></script> 
    <script type="text/javascript" lang="javascript" src="/Scripts/GrayParrot.Modals.js"></script> 
    <!-- Common -->
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <section class="panel">
	        <header class="panel-heading">
				<h2></h2>
			</header>
			<div class="panel-tools" align="right">
				<ul class="tooltip-area">
					<li><a href="javascript:void(0)" class="btn btn-collapse" title="Collapse"><i class="fa fa-sort-amount-asc"></i></a></li>
					<li><a href="javascript:void(0)" class="btn btn-reload"  title="Reload"><i class="fa fa-retweet"></i></a></li>
					<!-- <li><a href="javascript:void(0)" class="btn btn-close" title="Close"><i class="fa fa-times"></i></a></li> -->
				</ul>
			</div>
			<div class="panel-body">

                <!-- PUT YOUR CONTENT HERE -->
                <div id="crudDialog" title="" style="display:none"></div>

                <cc1:JQDataTable ID="JQDataTable1" runat="server" 
                     SelectionMode="Single" 
                     RenderScripts="false" 
                     BootstrapClasses="table table-hover table-bordered table-condensed">
                    <FeaturesConfig>
                        <Features>
                            <cc1:Searching Value="None"></cc1:Searching>
                            <cc1:AutoWitdh Value="true" />
                            <cc1:ScrollY Value="500" ScrollCollapse="true" />
                            <cc1:LengthChange Value="true" />
                            <cc1:Paging PagingType="FullNumbers" PageLength="20" />
                        </Features>
                    </FeaturesConfig>
                    <ControllerConfig Url="/api/<!-- URL OF CONTROLLER -->/Load" LoadingMode="OnLoad">
                    </ControllerConfig>
                    <ColumnsConfig Key="IDColore">
                        <Columns>
                            <!-- PUT HERE COLUMNS BASED ON CLASS PROPERTIES -->
                        </Columns>
                    </ColumnsConfig>
                    <Buttons>
                        <cc1:CrudAddButton Text="Aggiungi" Callback="LoadAddDialog" />
                        <cc1:CrudEditButton Text="Modifica" Callback="LoadEditDialog" />
                        <cc1:CrudDeleteButton Text="Cancella" Callback="DeleteDialog" />
                    </Buttons>
                </cc1:JQDataTable>

			</div>
			<!-- <footer class="panel-footer">
				<button type="submit" class="btn" data-color="#F4AD41">Submit</button>
				<button type="reset" class="btn">Cancel</button>
			</footer> -->
	</section>

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="LocaJavascript" runat="server">

  <% HttpContext.Current.Response.Write(this.JQDataTable1.RenderScriptsManually()); %>

<script>
    function LoadAddDialog() {

        $("#iframeCrud").prop('src', '$safeitemrootname$_CRUD.aspx').appendTo("#crudDialog");
        $("#iframeCrud").show();

        m_dialog = $("#crudDialog").dialog({
            title: 'Nuova Associazione',
            width: 'auto',
            height: 'auto',
            modal: true,
            close: function () {
                RedrawGrid(m_tableJQDataTable1);

                $("#iframeCrud").contents().remove();
                $('#iframeCrud').hide();
            }
        });
    }

    function LoadEditDialog() {

        var p = null;

        p = GetSelectedData(m_tableJQDataTable1).Id;

        var url = '$safeitemrootname$_CRUD.aspx?id=' + p;

        $("#iframeCrud").prop('src', url).appendTo("#crudDialog");
        $("#iframeCrud").show();

        m_dialog = $("#crudDialog").dialog({
            title: 'Modifica Associazione',
            width: 'auto',
            height: 'auto',
            modal: true,
            close: function () {
                RedrawGrid(m_tableJQDataTable1);

                $("#iframeCrud").contents().remove();
                $('#iframeCrud').hide();
            }
        });
    }

    function DeleteDialog() {
        var p = null;

        p = GetSelectedData(m_tableJQDataTable1).Id;

        var url = '/api/<!-- URL OF CONTROLLER -->/Delete';

        $("#crudDialog").html("Confermi la cancellazione dell'elemento con codice: " + p + " ?");

        // Define the Dialog and its properties.
        $("#crudDialog").dialog({
            resizable: false,
            modal: true,
            title: "Cancella elemento",
            height: 250,
            width: 400,
            buttons: {
                "Yes": function () {
                    $(this).dialog('close');

                    $.ajax({
                        type: "POST",
                        url: url,
                        data: JSON.stringify({ id: p }),
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (response) {
                            RedrawGrid(m_tableJQDataTable1);

                            alert(response);
                        },
                        failure: function (response) {
                            alert(response);
                        }
                    });
                },
                "No": function () {
                    $(this).dialog('close');
                }
            }
        });
    }
</script>

</asp:Content>